package com.web44.spring.mapper.impl;

import com.web44.spring.mapper.IBookMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

/**
 * @Title: BookMapper
 * @Description:
 * @Auther: py
 * @Version: 1.0
 * @create 2024/1/10 14:55
 */
@Repository
public class BookMapper implements IBookMapper {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public double queryBookPriceById(int bookId) {
        String sql = "select price from t_book where book_id = ?";
        double price = jdbcTemplate.queryForObject(sql,double.class,bookId);
        return price;
    }

    @Override
    public void updateBookStoreById(int bookId) {
        String sql = "update t_book set stock = stock-1 where book_id = ?";
        jdbcTemplate.update(sql,bookId);

    }
}
